﻿using System;

namespace 三式
{
    class Program
    {
        static void Main(string[] args)
        {
            Robot robot = new Robot();
            Player player = new Player();
            Referee referee = new Referee();
            Teller teller = new Teller();
            int x;
            int Winner;
            string str;
            bool PD;
            bool PD1;
            while (true)
            {
                PD = true;
                PD1 = true;
                Console.WriteLine("*******************欢迎进入游戏世界*******************");
                Console.WriteLine();
                Console.WriteLine("******************");
                Console.WriteLine("*****猜拳开始*****");
                Console.WriteLine("******************");
                Console.WriteLine("出拳规则：1.石头  2.剪刀  3.布");
                Console.WriteLine("请选择你的对手：（1.刘备  2.孙权  3.曹操）");
                while (true)
                {
                    str = Console.ReadLine();
                    if (str == "1" || str == "2" || str == "3")
                    {
                        robot.RobotName(str);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("请输入正确的号码！");
                        continue;
                    }
                }
                Console.WriteLine("请输入你的名字：");
                player.PlayerName(Console.ReadLine());
                teller.VS(robot.Name, player.Name);
                while (PD)
                {
                    Console.WriteLine("开始游戏吗？（y/n）");
                    while (true)
                    {
                        str = Console.ReadLine();
                        if (str == "y" || str == "n")
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("输入错误，请重新输入！");
                            continue;
                        }
                    }
                    if (str == "y")
                    {
                        while (PD1)
                        {
                            Console.WriteLine("请出拳： 1.石头  2.剪刀  3.布");
                            while (true)
                            {
                                str = Console.ReadLine();
                                if (str == "1" || str == "2" || str == "3")
                                {
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine("输入错误，请重试！( 1.石头  2.剪刀  3.布)");
                                    continue;
                                }
                            }
                            x = int.Parse(str);
                            player.PlayerPunch(x);//记录玩家出拳Id
                            Random random = new Random();
                            int y = random.Next(1, 4);
                            robot.RobotPunch(y);//记录机器人出拳Id
                            Winner = referee.PK(player.PunchId, robot.PunchId);
                            teller.Say(Winner, player.Name, robot.Name, player.PunchName, robot.PunchName);
                            Console.WriteLine("继续游戏吗？（y/n）");
                            while (true)
                            {
                                str = Console.ReadLine();
                                if (str == "y")
                                {
                                    break;
                                }
                                else if (str == "n")
                                {
                                    teller.Over(player.Name, robot.Name, referee.Round, referee.Deuce,referee.PlayerWin, referee.RobotWin);
                                    PD1 = false;
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine("输入错误，请重试！");
                                    continue;
                                }
                            }

                        }
                        break;
                    }
                    else if (str == "n")
                    {
                        Console.WriteLine();
                        Console.WriteLine("请输入：1.继续游戏  2.退出程序");
                        str = Console.ReadLine();
                        while (true)
                        {
                            if (str == "1") {  break; }
                            else if (str == "2") { Environment.Exit(0); }
                            else
                            {
                                Console.WriteLine("输入错误，请重新输入！");
                                continue;
                            }
                        }
                    }
                }
                Console.WriteLine();
                Console.WriteLine("请输入：1.重新开始游戏  2.退出程序");
                str = Console.ReadLine();
                while (true)
                {
                    if (str == "1")
                    {
                        break;
                    }
                    else if (str == "2")
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.WriteLine("输入错误，请重新输入！");
                        continue;
                    }
                }
            }
        }
    }
}
